package com.guyu.plugin.redisson.handler;

import com.baomidou.lock.exception.LockFailureException;
import com.guyu.common.core.entity.BizResult;
import com.guyu.common.core.exception.code.ErrorCodeEnum;
import com.guyu.common.web.util.GuyuServletUtils;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * Redis异常处理器
 */
@Slf4j
@Order(Ordered.HIGHEST_PRECEDENCE)
@RestControllerAdvice
public class RedisExceptionHandler {


    /**
     * Sa-分布式锁Lock4j异常
     */
    @ExceptionHandler(value = LockFailureException.class)
    public BizResult lockFailureExceptionHandler(HttpServletRequest request, LockFailureException e) {
        log.error("[GUYU]获取锁失败了, url:[ {} ], param:[ {} ], body:[ {} ]",
                request.getRequestURI(), GuyuServletUtils.getParams(request), GuyuServletUtils.getRequestBody(request), e);
        return BizResult.error(ErrorCodeEnum.CALL_LIMITED, "业务处理中，请稍后再试...");
    }
}
